import pprint

import requests
import execjs
cookies = {
    'privacyPolicyPopup': 'false',
    '__lg_stoken__': 'f74fa76fd756c33c66a949d7483807d0a529c168647bc3258c1b1ec53b4a307d6009757fed68666df1247e2e26230f4f4d0f1702a4febcf35babb0f411509392f4653de95524',
    'JSESSIONID': 'ABAABJAABDBABEFF5EBE79858E5268224A5EE09426B0A0F',
    'WEBTJ-ID': '20240810150353-1913b19d0e3c82-06501729ce221d-26001e51-2073600-1913b19d0e4bc1',
    'user_trace_token': '20240810150354-d133c00d-f12a-493c-99c1-34f791c20b3e',
    'LGUID': '20240810150354-7fa96d4d-aa2d-4363-8d1c-43d09d4cc952',
    'sensorsdata2015session': '%7B%7D',
    'TG-TRACK-CODE': 'index_code',
    'SEARCH_ID': '0d3d407f9b604cc287f855ceaca673e2',
    'X_MIDDLE_TOKEN': 'ba3aa272719b1660a72129343136e9fb',
    'gate_login_token': 'v1####c6c98cca27d02af50b34149c15bb8343f1e2b26de5e706b24867efe4a708d3ca',
    '_putrc': '8B161A51F69B3D31123F89F2B170EADC',
    'login': 'true',
    'unick': '%E7%94%A8%E6%88%B70545',
    'hasDeliver': '0',
    'privacyPolicyPopup': 'false',
    'X_HTTP_TOKEN': '94f5006dafacab3c6204923271b053423ed2c404e9',
    'LGRID': '20240811010147-b0650a17-ed0a-4adc-b9bb-0f4bed3c3a58',
    '__RESUME_COMPLETE_POPOVER__': '1',
    'sensorsdata2015jssdkcross': '%7B%22distinct_id%22%3A%221913b19d8b36ab-0f11ae8cb2486-26001e51-2073600-1913b19d8b4633%22%2C%22first_id%22%3A%22%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E4%BB%98%E8%B4%B9%E5%B9%BF%E5%91%8A%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%2C%22%24latest_referrer%22%3A%22%22%2C%22%24latest_utm_source%22%3A%22pc_search_right_jljx_1%22%2C%22%24os%22%3A%22Windows%22%2C%22%24browser%22%3A%22Chrome%22%2C%22%24browser_version%22%3A%22127.0.0.0%22%7D%2C%22%24device_id%22%3A%221913b19d8b36ab-0f11ae8cb2486-26001e51-2073600-1913b19d8b4633%22%7D',
}

headers = {
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive',
    'Origin': 'https://www.lagou.com',
    'Pragma': 'no-cache',
    'Referer': 'https://www.lagou.com/wn/',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-origin',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36',
    'X-K-HEADER': '1Nm2xxn26N6vBlwooI58QwGzYs2Uz78n3gt9W3Enpms5+QF7h001SHADyaTvvAnW',
    'X-S-HEADER': 'XIb5HDl70ubuTvkfSQEjOrcxoljoRx2hwBNOAxUGh7R6Q4MYi+QnwFKX7F8sF6NLNDP033BiQXjDxedbxOxUJYhD8pkWuimW2KFyHkpReoUBRsh9mkjLr1q6FD0gShLHMyqLPDlfDHEs8sJimt6FI4rkco0Za0nF8Q1JntOjs4fWjvUNzW0dOYTPrA+mkzl7cB9oAZ4iCdshfeXCbtCv6wN/aA1i45KIqeRbfQz538DG0WNESRP7uQF1OzXQ6IvS',
    'X-SS-REQ-HEADER': '{"secret": "1Nm2xxn26N6vBlwooI58QwGzYs2Uz78n3gt9W3Enpms5+QF7h001SHADyaTvvAnW"}',
    'accept': 'application/json, text/plain, */*',
    'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
    'sec-ch-ua': '"Not)A;Brand";v="99", "Google Chrome";v="127", "Chromium";v="127"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
    'traceparent': '00-c351cb0307bf6d56e950c500ba46fdcb-0834948a5c4927b7-01',
    'x-anit-forge-code': 'c9fc25fe-3b24-400d-ba10-581a553ad3d6',
    'x-anit-forge-token': 'eaca12f3-5e73-4890-ad3e-613b30a1a84d',
}

data = {
    'data': 'wONnWb+bTQWYQyDnIk+5Di60OGdVUavdrZnhrWb4AkPR7fCG01CTCJw0YXBk8q+P5LV8IG/ISXh/bW5pnfAqaNy8cXsTcDycB2EMwnYprumWywois1Qa+8ZKHioRMYZ5/zjvxdwkpXOV6wBaJUvgwgGSRTL0G25/qN6XKSUTXXA='
}

response = requests.post('https://www.lagou.com/jobs/v2/positionAjax.json', cookies=cookies, headers=headers, data=data)
print(response.text)
print(len(response.json()['data']))
data = execjs.compile(open('./spider.js', 'r', encoding='utf-8').read()).call('getData', response.json()['data'])
# print("解密后的响应:", data)
pprint.pprint(data)
